<?php

namespace app\common\model;

use think\Model;

class UserVerified extends Model
{
    // 表名
    protected $name = 'user_verified';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'status_text',
        'create_time_text'
    ];
    

    const STATUS_W = 1;
    const STATUS_Y = 2;
    const STATUS_N = 3;
    
    public static $_status = [
        self::STATUS_W => '待审核',
	    self::STATUS_Y => '审核通过',
	    self::STATUS_N => '审核失败'
    ];
    
    public function getStatusList()
    {
        return self::$_status;
    }     


    public function getStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['create_time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }

    public function user(){
    	return $this->belongsTo('user', 'user_id', 'id', '', 'LEFT')->setEagerlyType(0);
    }

}
